import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'
import routes from "./routers"

Vue.use(VueRouter)



const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 定义路由栈 用于判断当前页面是否拥有上级页面
 
var routeStack = ["/"];

//跳转的方法 replaeRoute 切换顶层路由对象
function repaceRoute(path){
  routeStack.pop();
  routeStack.push(path);
  router.replace(path)
}

//跳转下级页面
function pushRouteByQuery(path,params){
  routeStack.push(path);
  router.push({
    path:path,
    query:params
  })
}

function pushRouteByName(name,params){
  routeStack.push(name)
  router.push({
    name:name,
    params:params
  })
}

function backRoute(){
  routeStack.pop();
  router.back();
}


// router添加对应的方法
router.repaceRoute = repaceRoute;
router.pushRouteByQuery = pushRouteByQuery;
router.pushRouteByName = pushRouteByName;
router.backRoute = backRoute;
router.routeStack = routeStack;


export default router
